#include "DataOutput.h"
#include "lang/String.h"
using namespace yzrilyzr_lang;
namespace yzrilyzr_io{
	void DataOutput::writeBoolean(bool v){
		writeBuffer[0]=v?1:0;
		write(writeBuffer, 0, 1);
	}
	void DataOutput::writeByte(int8_t v){
		writeBuffer[0]=v;
		write(writeBuffer, 0, 1);
	}
	void DataOutput::writeUnsignedByte(uint8_t v){
		writeBuffer[0]=v;
		write(writeBuffer, 0, 1);
	}
	void DataOutput::writeShort(int16_t v){
		ByteConvert::putShort(writeBuffer, 0, v, bigEndian);
		write(writeBuffer, 0, 2);
	}
	void DataOutput::writeUnsignedShort(uint16_t v){
		ByteConvert::putUnsignedShort(writeBuffer, 0, v, bigEndian);
		write(writeBuffer, 0, 2);
	}
	void DataOutput::writeInt(int32_t v){
		ByteConvert::putInt(writeBuffer, 0, v, bigEndian);
		write(writeBuffer, 0, 4);
	}
	void DataOutput::writeUnsignedInt(uint32_t v){
		ByteConvert::putUnsignedInt(writeBuffer, 0, v, bigEndian);
		write(writeBuffer, 0, 4);
	}
	void DataOutput::writeLong(int64_t v){
		ByteConvert::putLong(writeBuffer, 0, v, bigEndian);
		write(writeBuffer, 0, 8);
	}
	void DataOutput::writeUnsignedLong(uint64_t v){
		ByteConvert::putUnsignedLong(writeBuffer, 0, v, bigEndian);
		write(writeBuffer, 0, 8);
	}
	void DataOutput::writeFloat(float v){
		ByteConvert::putFloat(writeBuffer, 0, v, bigEndian);
		write(writeBuffer, 0, 4);
	}
	void DataOutput::writeDouble(double v){
		ByteConvert::putDouble(writeBuffer, 0, v, bigEndian);
		write(writeBuffer, 0, 8);
	}
	void DataOutput::writeUTF(const String & v){
		u_index len=v.length();
		writeShort(len);
		auto bytes=v.getBytes(StringEncoding::UTF8);
		write(bytes);
	}
}